package com.soooft.tickey.service.impl;

import com.soooft.tickey.dao.UserDao;
import com.soooft.tickey.po.User;
import com.soooft.tickey.service.UserService;
import com.soooft.tickey.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @description
 * @author: Fanxl
 * @date: Created in 2017/9/18 10:23
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public UserVO getOperator(String userId) {
        User operator = userDao.getById(userId);
        BigDecimal balance = new BigDecimal(0.00);
        UserVO operatorVO = new UserVO();
        BeanUtils.copyProperties(operator, operatorVO);
        operatorVO.setHead(operator.getPhoto());
        operatorVO.setBalance(balance);
        return operatorVO;
    }

    @Override
    public User getByCode(String code) {
        return userDao.getByCode(code);
    }

    @Override
    public User getByOpenId(String openId) {
        return userDao.getByOpenId(openId);
    }

    @Override
    public User getById(String id) {
        return userDao.getById(id);
    }

   
    @Override
    public boolean save(User operator) {
        return userDao.insertSelective(operator)>0;
    }

    @Override
    public boolean update(User user) {

        return userDao.updateByPrimaryKeySelective(user)>0;
    }


}
